package com.ssss.template.java8Template;

import org.apache.commons.lang3.RandomUtils;

import java.math.BigDecimal;
import java.util.function.Consumer;

/**
 * java8 函数式编程实现模板方法
 */
public class BankBusinessHandler {

    private void execute(Consumer<BigDecimal> consumer){
        getNumber();
        consumer.accept(new BigDecimal("20"));
        judge();
    }

    private void getNumber() {
        System.out.println("number-00"+ RandomUtils.nextInt());
    }


    private void judge() {
        System.out.println("give a praised");
    }


    // 存钱
    public void save(BigDecimal amount){
        execute(a -> System.out.println("save "+amount));
    }

    // 取钱
    public void draw(BigDecimal amount){
        execute(a -> System.out.println("draw "+amount));
    }

    // 理财
    public void moneyManage(BigDecimal amount){
        execute(a -> System.out.println("manage "+amount));
    }


    public static void main(String[] args) {
        BankBusinessHandler bankBusinessHandler = new BankBusinessHandler();
        bankBusinessHandler.save(new BigDecimal("1000"));
        System.out.println("----");
        bankBusinessHandler.moneyManage(new BigDecimal("3000"));

        System.out.println("----");
        bankBusinessHandler.draw(new BigDecimal("30"));
    }

}
